home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / basic / bitstuf.com / BITTEST.BAS < prev    next >
Encoding:
BASIC Source File  |  1989-08-12  |  1.1 KB  |  40 lines

  1.       DEFINT A-Z
  2.  
  3. '  Start this as "qb /Lbitstuff bittest" to use the supplied .QLB
  4. '  See the .DOC file and the MASM source file for more details
  5.  
  6.       DECLARE SUB SetBit (bitnum%, word%)
  7.       DECLARE SUB ClearBit (bitnum%, word%)
  8.       DECLARE SUB ToggleBit (bitnum%, word%)
  9.       DECLARE FUNCTION BitState% (bitnum%, word%)
  10.  
  11.       DECLARE FUNCTION BitStr$ (word%)
  12.  
  13.       DECLARE FUNCTION BitVal& (ones$)
  14.  
  15.       '''DECLARE FUNCTION BitVal% (ones$)
  16.  
  17. ' Change the declaration as shown above to see the difference in how QB
  18. ' interprets the same 16 bit quantity when it thinks it's an integer.
  19.  
  20.       CLS
  21.  
  22.       v$ = "│"
  23.       FOR k = 0 TO 16   'bit positions 1 through 16
  24.          a = -1
  25.          b = 0
  26.          ClearBit k, a: SetBit k, b
  27.          a$ = BitStr(a)
  28.          b$ = BitStr(b)
  29.          PRINT b, b$; v$; BitVal(b$), a, a$; v$; BitVal(a$)
  30.       NEXT
  31.  
  32.       bt$ = "10101"
  33.       PRINT
  34.       PRINT "States of the individual bits in "; bt$; "..."
  35.       PRINT
  36.       FOR k = 1 TO 5
  37.          PRINT BitState(k, BitVal(bt$)),
  38.       NEXT
  39.  
  40.